package com.netty.io.nio;

import java.io.File;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;


/**
 * 将文件的数据读取显示在控制台
 * 将文件的内容先写入channel
 * 通过channel将数据读取到buffer
 * 随后将buffer的数据转为字符串打印
 * */
public class NioInputExample {

    public static void main(String[] args) throws Exception {

        File file = new File("D://nio2.txt");

        FileInputStream fileInputStream = new FileInputStream(file);

        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());

        channel.read(byteBuffer);

        System.out.println(new String(byteBuffer.array()));

        fileInputStream.close();
    }


}
